package com.kamikaze;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class ModificationServlet
 */
public class ModificationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ModificationServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String user_id = request.getParameter("user_id");
		String user_pw = request.getParameter("user_pw");
		String user_tel = request.getParameter("user_tel");
		String user_mobile = request.getParameter("user_mobile");
		String user_address = request.getParameter("user_address");
		Member member = new Member(user_id, user_pw);
		// 取得修改的欄位
		Modification mod = new Modification(user_tel, user_mobile, user_address);
		session.setAttribute("Modification", mod);
		// 取得登入的欄位
		if (!member.login()) {
			response.sendRedirect("modification.jsp");
			if(mod.update()){
// 修改成功後要轉址?
				System.out.println("修改成功");
			}
		}else{
			response.sendRedirect("index.jsp?f=7");
		}
		
	}
}
